package com.pactera.jep.service.sys.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.pactera.jep.autoconfigure.web.controller.BaseRestController;
import com.pactera.jep.commons.StringUtils;
import com.pactera.jep.core.code.YesNo;
import com.pactera.jep.core.context.Context;
import com.pactera.jep.core.entity.Identity;
import com.pactera.jep.core.exception.ServiceException;
import com.pactera.jep.orm.*;
import com.pactera.jep.sys.code.NotifyConfigResult;
import com.pactera.jep.sys.code.NotifyConfigType;
import com.pactera.jep.sys.code.NotifyStatus;
import com.pactera.jep.sys.code.StaffNotifyStatus;
import com.pactera.jep.sys.dto.StaffNotifyDto;
import com.pactera.jep.sys.model.Notify;
import com.pactera.jep.sys.model.NotifyConfig;
import com.pactera.jep.sys.model.Staff;
import com.pactera.jep.sys.model.StaffNotify;
import com.pactera.jep.sys.service.*;
import com.pactera.jep.web.code.WebCode;
import com.pactera.jep.web.util.RequestUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@Api(value = "系统公告")
@RequestMapping("/notify")
public class NotifyRestController extends BaseRestController<Notify>{
Logger logger = LoggerFactory.getLogger(NotifyRestController.class);

    @Autowired
    private NotifyService notifyService;

    @Autowired
    private StaffNotifyService staffNotifyService;

    @Autowired
    private StaffService staffService;

    @Autowired
    private AttachmentService		attachmentService;

    @Autowired
    private NotifyConfigService notifyConfigService;
	/**
	 * 为列表页面做数据准备
	 */

	@Override
	protected void prepareQuery(String token, Page<Notify> page, List<Filter> filters, List<Order> orders, HttpServletRequest request) {

        orders.add(new Order("sendTime", OrderType.DESC));
        String staffCode = getStaffCode(token);
        filters.add(new Filter("sender", staffCode));
		notifyService.query(page, filters, orders);
	}


	@ApiOperation(value = "查询当前用户发出的系统公告")
	@GetMapping(value = "/queryNotify")
	public Map<String, Object> queryNotify(@RequestHeader("x-user-token") String token, Page<Notify> page,  HttpServletRequest request)
	{
	    //已发送的,发送者是自己
        return getMap(token, page, request,NotifyStatus.SEND.getValue(),NotifyConfigType.ANNOUNCE.getValue());
	}

    @ApiOperation(value = "查询最近三天的最新一条系统公告")
    @GetMapping(value = "/queryNotifyLimit1")
    public Map<String, Object> queryNotifyLimit1( Page<Notify> page,  HttpServletRequest request)
    {
        List<Order> orders = RequestUtils.buildOrders(request);
        orders.add(new Order("sendTime", OrderType.DESC));
        List<Filter> filters = RequestUtils.buildFilters(request);
        filters.add(new Filter("type", NotifyConfigType.ANNOUNCE.getValue()));
        String staffName = Context.getIdentityContext().getIdentity().getName();//超级管理员
        filters.add(new Filter("status", NotifyStatus.SEND.getValue()));//状态
        notifyService.queryNotify(page, filters, orders);
        List<Notify> collect = page.getResult();
        Map<String, Object> result = new HashMap<String, Object>();
        List<Notify> limit = collect.stream().limit(1).filter(n -> {
            //三天前
            Date ago = DateUtils.addDays(new Date(), -3);
            //发送时间大于三天前
            return n.getSendTime().getTime() >= ago.getTime();
        }).collect(Collectors.toList());
        page.setResult(limit.isEmpty() ? null : limit);
        result.put("staffName", staffName);
        result.put("pageNumber", page.getPageNumber());
        result.put("pages", page.getPages());
        result.put("pageSize", page.getPageSize());
        result.put(RESULT_TOTAL, page.getTotal());
        result.put(RESULT_ROWS, page.getResult());
        return result;
    }

    @ApiOperation(value = "查询所有的系统公告")
    @GetMapping(value = "/queryNotifyAll")
    public Map<String, Object> queryNotifyAll(@RequestHeader("x-user-token") String token, Page<Notify> page,  HttpServletRequest request)
    {
        //查询所有的系统公告
        List<Order> orders = RequestUtils.buildOrders(request);
        orders.add(new Order("sendTime", OrderType.DESC));
        List<Filter> filters = RequestUtils.buildFilters(request);
        filters.add(new Filter("type", NotifyConfigType.ANNOUNCE.getValue()));
        filters.add(new Filter("status", NotifyStatus.SEND.getValue()));//状态
        notifyService.queryNotify(page, filters, orders);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageNumber", page.getPageNumber());
        result.put("pages", page.getPages());
        result.put("pageSize", page.getPageSize());
        result.put(RESULT_TOTAL, page.getTotal());
        List<Notify> collect = page.getResult();
        //公告
        if (NotifyConfigType.ANNOUNCE.getValue().equals(NotifyConfigType.ANNOUNCE.getValue())) {
            collect = collect.stream().map((notice -> {
                if (StringUtils.isEmpty(notice.getReceiver())) {
                    notice.setReceiver("all");
                    notice.setReceiverName("所有人");
                }
                return notice;
            })).collect(Collectors.toList());
        }
        result.put(RESULT_ROWS, collect);
        return result;
    }

    private Map<String, Object> getMap(String token, Page<Notify> page, HttpServletRequest request,String status,String notifyConfigType ) {
        List<Order> orders = RequestUtils.buildOrders(request);
        orders.add(new Order("sendTime", OrderType.DESC));
        List<Filter> filters = RequestUtils.buildFilters(request);
        String staffCode = getStaffCode(token);//superAdmin
        filters.add(new Filter("sender", staffCode));//发送者
        filters.add(new Filter("type", notifyConfigType));
        String staffName = Context.getIdentityContext().getIdentity().getName();//超级管理员
        filters.add(new Filter("status", status));//状态
        notifyService.queryNotify(page, filters, orders);
        Map<String, Object> result = new HashMap<String, Object>();
        //公告
        List<Notify> collect = page.getResult();
        if (NotifyConfigType.ANNOUNCE.getValue().equals(notifyConfigType)) {
            collect = collect.stream().map((notice -> {
                if (StringUtils.isEmpty(notice.getReceiver())) {
                    notice.setReceiver("all");
                    notice.setReceiverName("所有人");
                }
                return notice;
            })).collect(Collectors.toList());
            page.setResult(collect);
        }
        result.put("staffName", staffName);
        result.put("pageNumber", page.getPageNumber());
        result.put("pages", page.getPages());
        result.put("pageSize", page.getPageSize());
        result.put(RESULT_TOTAL, page.getTotal());
        result.put(RESULT_ROWS, page.getResult());
        return result;
    }

    @ApiOperation(value = "查询当前用户的草稿系统公告")
    @GetMapping(value = "/queryNotifyDraft")
    public Map<String, Object> queryNotifyDraft(@RequestHeader("x-user-token") String token, Page<Notify> page,  HttpServletRequest request)
    {
        return getMap(token, page, request,NotifyStatus.DRAFT.getValue(),NotifyConfigType.ANNOUNCE.getValue());
    }

    @ApiOperation(value = "查询当前用户的已发送私信")
    @GetMapping(value = "/queryMessage")
    public Map<String, Object> queryMessage(@RequestHeader("x-user-token") String token, Page<Notify> page,  HttpServletRequest request)
    {
        Map<String, Object> map = getMap(token, page, request, NotifyStatus.SEND.getValue(), NotifyConfigType.MESSAGE.getValue());
        List<Notify> notifies = (List<Notify>) map.get(RESULT_ROWS);
        List<StaffNotifyDto> collect = notifies.stream().map(notify -> {
            List<Filter> filters = new ArrayList();
            filters.add(new Filter("notifyId", notify.getId()));
            filters.add(new Filter("status", StaffNotifyStatus.INBOX.getValue()));
            StaffNotifyDto dto = new StaffNotifyDto();
            StaffNotify staffNotify = staffNotifyService.get(filters);
            BeanUtils.copyProperties(notify,dto);
            if (Objects.nonNull(staffNotify)) {
                dto.setStaffNotifyId(staffNotify.getId());
                dto.setIsRead(staffNotify.getRead());
            }
            return dto;
        }).filter(dto-> StringUtils.isNotEmpty(dto.getStaffNotifyId())).collect(Collectors.toList());
        map.put(RESULT_ROWS, collect);
        return map;
    }

    @ApiOperation(value = "查询当前用户的草稿箱私信")
    @GetMapping(value = "/queryMessageDraft")
    public Map<String, Object> queryMessageDraft(@RequestHeader("x-user-token") String token, Page<Notify> page,  HttpServletRequest request)
    {
        return getMap(token, page, request,NotifyStatus.DRAFT.getValue(),NotifyConfigType.MESSAGE.getValue());
    }

    /**
     * 保存公告(发送)
     * @param notify
     * @param
     * @return
     */
    @ApiOperation(value = "保存公告(发送)")
    @PutMapping(value = "/saveAnnounce")
    public Map<String, Object> saveAnnounce(@RequestBody Notify notify) {
        Map<String, Object> tips = new HashMap<String, Object>();
        try
        {
            /*设置发件人，及基础信息*/
            extracted(notify);
            notify.setStatus(NotifyStatus.SEND.getValue());
            //创建
            notifyService.createAnnounce(notify);
            tips.put(WebCode.SUCCESS, true);
            tips.put(WebCode.MSG, WebCode.SUCCESS_SEND);
            tips.put("id", notify.getId());
        }
        catch (ServiceException e)
        {
            logger.info(e.getMessage());
            tips.put(WebCode.SUCCESS, false);
            tips.put(WebCode.MSG, WebCode.FAILURE_SEND);
        }
        return tips;
    }

    /**
     * 查看页面
     * @param id
     * @param
     * @return
     */
    @ApiOperation(value = "查询系统公告")
    @GetMapping(value = "/view/{id}")
    public Notify view(@PathVariable  String id) {
        return notifyService.get(id);
    }
    /**
     * 删除
     * @param
     * @return
     */
    @ApiOperation(value = "删除系统公告")
    @DeleteMapping(value = "/remove")
    public Map<String, Object> remove(@RequestBody String ids){

        Map<String, Object> tips = new HashMap<String, Object>();
        try
        {
            notifyService.remove(ids);
            tips.put(WebCode.SUCCESS, true);
            tips.put(WebCode.MSG, WebCode.SUCCESS_DELETE);
        }
        catch (ServiceException e)
        {
            logger.info(e.getMessage());
            tips.put(WebCode.SUCCESS, false);
            tips.put(WebCode.MSG, WebCode.FAILURE_DELETE);
        }

        return tips;
    }
    /**
     * 逻辑删除
     * @param
     * @return
     */
    @ApiOperation(value = "逻辑删除")
    @PostMapping(value = "/deleteFlag")
    public Map<String, Object> deleteFlag(@RequestBody String ids){

        Map<String, Object> tips = new HashMap<String, Object>();

        try
        {
            notifyService.deleteFlag(ids);
            tips.put(WebCode.SUCCESS, true);
            tips.put(WebCode.MSG, WebCode.SUCCESS_DELETE);
        }
        catch (ServiceException e)
        {
            logger.info(e.getMessage());
            tips.put(WebCode.SUCCESS, false);
            tips.put(WebCode.MSG, WebCode.FAILURE_DELETE);
        }

        return tips;
    }
    /**
     * 保存私信
     * @param notify
     * @return
     */
    @ApiOperation(value = "保存私信")
    @PutMapping(value = "/saveMessage")
    public Map<String, Object> saveMessage(@RequestBody Notify notify) {
        Map<String, Object> tips = new HashMap<String, Object>();

        try
        {
            /*设置发件人，及基础信息*/
            Identity identity = Context.getIdentityContext().getIdentity();
            notify.setSender(identity.getId());
            notify.setSenderName(identity.getName());
            notify.setSendTime(new Date());
            notify.setStatus(NotifyStatus.SEND.getValue());
            notify.setType(NotifyConfigType.MESSAGE.getValue());
            notify.setCreateTime(notify.getSendTime());
            notify.setCreateById(identity.getId());
            notify.setCreateByName(identity.getName());
            if("".equals(notify.getId())){
                notify.setId(null);
            }
            long i = attachmentService.count(new Filter.Builder().eq("entityId", notify.getId()).build());
            if(i > 0){
                notify.setIsUpload(YesNo.YES.getValue());
            }else{
                notify.setIsUpload(YesNo.NO.getValue());
            }

            /*设置收件人*/
            Map<String, String> remind = this.getStaffMsgNotifyConfig(notify.getReceiver(), notify.getSender());
            notify.setReceiverName(staffService.getNameByCode(notify.getReceiver()));

            notifyService.createMessage(notify, remind);

            /*设置消息提示*/
            String refuseRecMsg = remind.get("refuseRecMsgName");
            String blacklist = remind.get("blacklistName");
            if(StringUtils.isNotEmpty(remind.get("newReceiver")) &&
                    (StringUtils.isNotEmpty(refuseRecMsg) || StringUtils.isNotEmpty(blacklist)))
            {
                tips.put("msg", "私信发送部分成功，用户："+ refuseRecMsg +" "+ blacklist +"拒绝接收私信！");
            }
            else if(StringUtils.isEmpty(remind.get("newReceiver")) &&
                    (StringUtils.isNotEmpty(blacklist) || StringUtils.isNotEmpty(blacklist)))
            {
                tips.put("msg", "私信发送成功，用户接收私信失败！用户："+ refuseRecMsg +" "+ blacklist +"拒绝接收私信！");
            }else{
                tips.put(WebCode.MSG, WebCode.SUCCESS_SEND);
            }
            tips.put(WebCode.SUCCESS, true);
            tips.put("id", notify.getId());
        }
        catch (ServiceException e)
        {
            logger.info(e.getMessage());
            tips.put(WebCode.SUCCESS, false);
            tips.put(WebCode.MSG, WebCode.FAILURE_SEND);
        }
        return tips;
    }

    /**
     * 创建提醒
     * @param notify
     * @return
     */
    @ApiOperation(value = "创建提醒")
    @PutMapping(value = "/createreMinderMessage")
    public Map<String, Object> createreMinderMessage(@RequestBody Notify notify) {
        Map<String, Object> tips = new HashMap<String, Object>();
        try
        {
            /*设置发件人，及基础信息*/
            Identity identity = Context.getIdentityContext().getIdentity();
            notifyService.createRemind(identity.getId(), notify.getSubject(), notify.getContent());
            tips.put("msg", "提醒创建成功");
            tips.put(WebCode.SUCCESS, true);
            tips.put("id", notify.getId());
        }
        catch (ServiceException e)
        {
            logger.info(e.getMessage());
            tips.put(WebCode.SUCCESS, false);
            tips.put(WebCode.MSG, WebCode.FAILURE_SEND);
        }
        return tips;
    }

    /**
     * 查询所有提醒
     */
    @ApiOperation(value = "查询提醒")
    @GetMapping(value = "/queryMinderMessageAll")
    public Map<String, Object> queryMinderMessageAll(Page<StaffNotifyDto> page, HttpServletRequest request) {

        List<Order> orders = RequestUtils.buildOrders(request);
        List<Filter> filters = RequestUtils.buildFilters(request);
        Map<String, Object> result = new HashMap<String, Object>();

        orders.add(new Order("createTime", OrderType.DESC));

            String staffCode = Context.getIdentityContext().getIdentity().getId();
            filters.add(new Filter("staffCode", staffCode));
            List<String> types = new ArrayList<>();
            types.add(NotifyConfigType.REMIND.getValue());
            filters.add(new Filter("type",types ));
            filters.add(new Filter("status", StaffNotifyStatus.INBOX.getValue()));

            staffNotifyService.queryNotifyByStaffCode(page, filters, orders);

            result.put("pageNumber", page.getPageNumber());
            result.put("staffName", Context.getIdentityContext().getIdentity().getName());
            result.put("pages", page.getPages());
            result.put("pageSize", page.getPageSize());
            result.put(RESULT_TOTAL, page.getTotal());
            result.put(RESULT_ROWS, page.getResult());
            return result;

    }




    /**
     * 保存公告草稿
     * @param notify
     * @return
     */
    @ApiOperation(value = "保存公告草稿")
    @PutMapping(value = "/saveAnnounceDraft")
    public Map<String, Object> saveAnnounceDraft(@RequestBody Notify notify) {
        Map<String, Object> tips = new HashMap<String, Object>();
        Boolean isExist = notifyService.exists(notify.getId());
        try
        {
            extracted(notify);
            if(isExist)
            {
                notifyService.update(notify);
            }
            else
            {
                notifyService.insert(notify);
            }
            tips.put(WebCode.SUCCESS, true);
            tips.put(WebCode.MSG, WebCode.SUCCESS_SAVE_DRAFT);
            tips.put("id", notify.getId());
        }
        catch (ServiceException e)
        {
            logger.info(e.getMessage());
            tips.put(WebCode.SUCCESS, false);
            tips.put(WebCode.MSG, WebCode.FAILURE_SAVE_DRAFT);
        }
        return tips;
    }
        //公告保存准备
    private void extracted(Notify notify) {
        Identity identity = Context.getIdentityContext().getIdentity();
        notify.setSender(identity.getId());
        notify.setSenderName(identity.getName());
        notify.setSendTime(new Date());
        notify.setStatus(NotifyStatus.DRAFT.getValue());
//        notify.setType(NotifyConfigType.ANNOUNCE.getValue());//前端传
        notify.setIsUpload(YesNo.NO.getValue());
        notify.setReceiver(this.getAnnounceReceiver(notify.getReceiver()));//
        notify.setReceiverName( "".equals(notify.getReceiver()) ? "" : staffService.getNameByCode(notify.getReceiver()));
        notify.setCreateTime(new Date());
        notify.setCreateById(identity.getId());
        notify.setCreateByName(identity.getName());
        if("".equals(notify.getId())){
            notify.setId(null);
        }
        if(StringUtils.isEmpty(notify.getSubject())){
            notify.setSubject("");
        }
        if(StringUtils.isNotEmpty(notify.getId())){
            long i = attachmentService.count(new Filter.Builder().eq("entityId", notify.getId()).build());
            if(i > 0){
                notify.setIsUpload(YesNo.YES.getValue());
            }
        }

    }

    /**
     * 保存私信草稿
     * @param notify
     * @return
     */
    @ApiOperation(value = "保存私信草稿")
    @PutMapping(value = "/saveMessageDraft")
    public Map<String, Object> saveMessageDraft(@RequestBody Notify notify) {

        Map<String, Object> tips = new HashMap<String, Object>();

        Boolean isExist = notifyService.exists(notify.getId());
        try
        {
            /*设置发件人*/
            Identity identity = Context.getIdentityContext().getIdentity();
            notify.setSender(identity.getId());
            notify.setSenderName(identity.getName());
            notify.setSendTime(new Date());
            notify.setStatus(NotifyStatus.DRAFT.getValue());
            notify.setType(NotifyConfigType.MESSAGE.getValue());
            notify.setIsUpload(YesNo.NO.getValue());

            notify.setReceiverName(staffService.getNameByCode(notify.getReceiver()));
            notify.setCreateById(identity.getId());
            notify.setCreateByName(identity.getName());
            notify.setCreateTime(new Date());
            if("".equals(notify.getId())){
                notify.setId(null);
            }
            if(StringUtils.isEmpty(notify.getSubject()))
                notify.setSubject("");

            if(isExist) //草稿状态下发送
            {
                long i = attachmentService.count(new Filter.Builder().eq("entityId", notify.getId()).build());
                if(i > 0){
                    notify.setIsUpload(YesNo.YES.getValue());
                }
                notifyService.update(notify);
            }
            else
            {
                notifyService.insert(notify);
            }

            tips.put(WebCode.SUCCESS, true);
            tips.put(WebCode.MSG, WebCode.SUCCESS_SAVE_DRAFT);
            tips.put("id", notify.getId());
        }
        catch (ServiceException e)
        {
            logger.info(e.getMessage());
            tips.put(WebCode.SUCCESS, false);
            tips.put(WebCode.MSG, WebCode.FAILURE_SAVE_DRAFT);
        }
        return tips;
    }
    /**
     * 获取发送者的通知配置值:<br>
     * 1.发送者是否在收件人的黑名单中<br>
     * 2.收件人是否设置拒绝接收私信
     * @param receiver
     * @param sender
     * @return
     */
    private Map<String, String> getStaffMsgNotifyConfig(String receiver, String sender){
        Map<String, String> result = new HashMap<String, String>();

        String newReceiver = "";
        String refuseRecMsg = "";
        String blacklist = "";

        String[] receiverArr = receiver.split(",");
        for (String staffCode : receiverArr)
        {
            /*获取收件人的配置信息*/
            NotifyConfig tmp = new NotifyConfig();
            tmp.setStaffCode(staffCode);
            NotifyConfig staffNotifyConfig = notifyConfigService.get(tmp);

            if(staffNotifyConfig != null)
            {
                /*收件人的配置信息中为接收私信，或没有黑名单、或没有将发件人设置为黑名单内*/
                if(!NotifyConfigResult.REFUSE.getValue().equals(staffNotifyConfig.getIsReceiveMsg())
                        && (staffNotifyConfig.getBlacklist() == null
                        || staffNotifyConfig.getBlacklist().indexOf(sender) == -1))
                {
                    newReceiver += staffCode + ",";
                }
                else if(NotifyConfigResult.REFUSE.getValue().equals(staffNotifyConfig.getIsReceiveMsg())) //拒绝接收私信
                {
                    refuseRecMsg += staffCode + ",";
                }
                else if(staffNotifyConfig.getBlacklist() != null
                        && staffNotifyConfig.getBlacklist().indexOf(sender) != -1) //在黑名单列表中
                {
                    blacklist += staffCode + ",";
                }
            }else{ //用户未配置，默认接收
                newReceiver += staffCode + ",";
            }
        }

        /*获取发件人是配置信息*/
        NotifyConfig senderConfig = new NotifyConfig();
        senderConfig.setStaffCode(sender);
        NotifyConfig staffNotifyConfig = notifyConfigService.get(senderConfig);
        if(staffNotifyConfig != null)
        {
            result.put("remindCfg", staffNotifyConfig.getIsReceiveRemind());
            result.put("messageCfg", staffNotifyConfig.getIsReceiveMsg());
        }
        else
        {
            result.put("remindCfg", NotifyConfigResult.RECEIVE.getValue());
            result.put("messageCfg", NotifyConfigResult.RECEIVE.getValue());
        }

        result.put("newReceiver", newReceiver);
        result.put("refuseRecMsgName", staffService.getNameByCode(refuseRecMsg));
        result.put("blacklistName", staffService.getNameByCode(blacklist));

        return result;
    }
    /*获取发公告的收件人*/
    private String getAnnounceReceiver(String receiver){

        String staffCodes = "";
        if(StringUtils.isNotEmpty(receiver))
        {
            if("all".equals(receiver))
            {
//                staffCodes = staffService.selectAllStaffCode();
                return staffCodes;
            }
            else
            {
                JSONObject obj = JSONObject.parseObject(receiver);
                String units = (String) obj.get("unitList");
                String roles = (String) obj.get("roleList");
                String staffs = (String) obj.get("staffList");
                staffCodes = staffService.selectStaffByUnitsAndRolesAndStaffs(units, roles, staffs);
            }
        }
        return staffCodes;
    }
    @ApiOperation(value = "草稿箱数量")
    @GetMapping(value = "/synch")
    public Map<String, Object> synch(){
        Map<String, Object> result = new HashMap<String, Object>();
        String staffCode = Context.getIdentityContext().getIdentity().getId();
        long draftUnsend = notifyService.count(
                new Filter.Builder().eq("sender", staffCode).
                        eq("status", NotifyStatus.DRAFT.getValue()).eq("type", NotifyConfigType.ANNOUNCE.getValue()).build());
        result.put("draftUnsend", draftUnsend);
        return result;
    }

    /**
     * 公告预览查询收件人
     * @param
     * @param
     * @return
     */
    @ApiOperation(value = "公告预览查询收件人")
    @GetMapping(value = "/previewReceiver/{receiver}")
    public Map<String, Object> previewReceiver(@PathVariable String receiver) {
        Map<String, Object> result = new HashMap<String, Object>();
        if(StringUtils.isNotEmpty(receiver))
        {
            String staffCode = this.getAnnounceReceiver(receiver);
            result.put("receiverName", staffService.getNameByCode(staffCode));
        }
        Identity identity = Context.getIdentityContext().getIdentity();
        result.put("senderName", identity.getName());
        return result;
    }

    @ApiOperation(value = "增加提醒")
    @PostMapping("/createRemind")
    public String createRemind(String receiver, String subject, String content) {
        return notifyService.createRemind(receiver, subject, content) + "";
    }

    @ApiOperation(value = "增加代办")
    @PostMapping("/createTodo")
    public String createTodo(String subject,
                          String content, String receiver, String target, String targetType, String action) {
        return notifyService.createTodo(subject, content, receiver, target, targetType, action) + "";
    }

    @ApiOperation(value = "增加代办到人")
    @PostMapping("/createTodoByStaff")
    public String createTodo(String subject,
                          String content, @RequestBody List<Staff> receiver, String target, String targetType, String action) {
        return notifyService.createTodo(subject, content, receiver, target, targetType, action)+"";
    }
}
